#include "utils.hpp"
#if WIN32
#include "win32_utility.hpp"
#else
#include <unistd.h>
#include <sys/stat.h>
#endif

namespace CodeGen  {

unsigned long long get_file_mtime(const std::string &file)
{
    unsigned long long ret = 0;
#if WIN32
    std::wstring wide_path = fromUtf8(file);
    HANDLE hFile = CreateFileW(wide_path.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, NULL, NULL);
    if (hFile) {
        FILETIME mTime;
        if (GetFileTime(hFile, NULL, NULL, &mTime)) {
            ret = ((unsigned long long)mTime.dwHighDateTime << 32) | mTime.dwLowDateTime;
        }
        CloseHandle(hFile);
    }
#else
    struct stat64 st;
    if (0 == stat64(file.c_str(), &st))
    {
        ret = st.st_mtim.tv_sec * 1'000'000'000 + st.st_mtim.tv_nsec;
    }
#endif
    return ret;
}


}
